#include "los_swtmr.h"
#include "ohos_init.h"
#include "osTest.h"

UINT32 g_soft_timer_id;

UINT32 g_count = 0;

VOID soft_timer_callback_func(UINT32 para)
{
    printf("para = %d\n", para);
    printf("++++Yang Zihao's soft_timer_callback_func %d\n", ++g_count);

    if(g_count >= para)
    {
        LOS_SwtmrStop(g_soft_timer_id);
    }
}

void soft_timer_demo()
{
    printf("++++Yang Zihao's soft_timer_demo start \n");
    
    UINT32 ret = LOS_SwtmrCreate(500,
    LOS_SWTMR_MODE_PERIOD,
    soft_timer_callback_func,
    &g_soft_timer_id, 3);

    if(ret != LOS_OK)
    {
        printf("++++Yang Zihao's soft timer create ret = %d\n", ret);
        return;
    }
    printf("++++Yang Zihao's soft timer create ok \n",ret);
    ret = LOS_SwtmrStart(g_soft_timer_id);

    if(ret != LOS_OK)
    {
        printf("++++Yang Zihao's soft timer start ret = %d\n", ret);
        return;
    }

    printf("++++Yang Zihao's soft timer start ok \n", ret);
}